package com.lenovo.session;

import com.lenovo.testreport.user.model.Userinfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;

/**
 * @author CJF
 * @date 2018/11
 * <p>
 * 权限检测
 */

@Service
public class LevelControl {

    @Autowired
    private RedisTemplate<Object, Object> redisTemplate;

    //管理员权限代码为10
    private final int ADMIN_LEVLE = 10;

    //判断是否拥有管理员权限
    public boolean checkAdminSession(HttpServletRequest request) {
        String sessionId = "Lenovo-sessionId:" + request.getSession().getId();
        Userinfo userinfo = (Userinfo) redisTemplate.opsForValue().get(sessionId);
        int level = userinfo.getLevel();
        if (level == ADMIN_LEVLE) {
            return true;
        } else {
            return false;
        }
    }

    public boolean checkUserSession(HttpServletRequest request) {
        return false;
    }

}
